package text;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.PasswordField;
import javafx.stage.Stage;
import javafx.scene.layout.*;

// 密码输入框(输入字符被掩盖)
public class PasswordFieldDemo extends Application { 
	private StackPane root = new StackPane();
	private PasswordField pf;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		root.setPadding(new Insets(50));
		
		pf = new PasswordField();
		pf.setPromptText("请输入密码（长度7位）");
		pf.setFocusTraversable(false);
		root.getChildren().addAll(pf);
		
		Scene scene = new Scene(root, 300, 200);
		stage.setScene(scene);
		stage.setTitle("密码输入框");
		stage.show();
		
		// 监听内容，保持7位
		pf.textProperty().addListener(e -> {
			if(pf.getText().length()>7) {
				pf.setText(pf.getText(0,7));   // [0,7)
			}
		});
	}
}





